package Screens;

import Utils.GameUtils;
import Utils.SoundManager;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.acumenvn.pent.MyPent;

public class SplashScreen implements Screen {
	// Variables
	Texture mTexture;
	TextureRegion mTextureRegion;
	SpriteBatch mBatch;
	MyPent mGame;
	Sound mClickSound;
	InputProcessor mInputP;
	float timeToLoad;
	
	public SplashScreen(MyPent game) {
		// TODO Auto-generated constructor stub
		this.mGame = game;
	}
	
	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl10.glClearColor(0, 0, 0, 1);
		Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		mBatch.begin();
		mBatch.draw(mTextureRegion, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		mBatch.end();
		
//		if(timeToLoad > 0) {
//			timeToLoad-= delta;
//			return;
//		}
//		
//		mGame.setScreen(new MainMenuScreen(mGame));
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		mTexture = new Texture("ImagesPOT/SplashScreen.png");
		mTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
		
		mTextureRegion = new TextureRegion(mTexture, 142, 177, 800, 600);
		
		mBatch = new SpriteBatch();
		Gdx.graphics.setContinuousRendering(false);
		Gdx.graphics.requestRendering();
		mClickSound = SoundManager.getInstance().getSoundSelectMenu();
		timeToLoad = 0.5f;
		mInputP = new InputProcessor() {
			
			@Override
			public boolean touchUp(int screenX, int screenY, int pointer, int button) {
				// TODO Auto-generated method stubGI
				return false;
			}
			
			@Override
			public boolean touchDragged(int screenX, int screenY, int pointer) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean touchDown(int screenX, int screenY, int pointer, int button) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean scrolled(int amount) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean mouseMoved(int screenX, int screenY) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean keyUp(int keycode) {
				// TODO Auto-generated method stub
				if(keycode == Keys.ENTER) {
					SoundManager.getInstance().playSound(mClickSound);
					mGame.setScreen(new MainMenuScreen(mGame));
					return true;
				}
				return false;
			}
			
			@Override
			public boolean keyTyped(char character) {
				// TODO Auto-generated method stub
				return false;
			}
			
			@Override
			public boolean keyDown(int keycode) {
				// TODO Auto-generated method stub
				return false;
			}
		};
		
		Gdx.input.setInputProcessor(mInputP);
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		mTexture.dispose();
	}

}
